package com.xcity.game.item.drop.impl;

import com.xcity.db.entity.Player;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.item.drop.RangeDrop;
import com.xcity.game.item.drop.listener.DropListener;
import com.xcity.game.item.drop.listener.StoneDropListener;

import naga.x.util.CommonUtils;

public class StoneDrop extends RangeDrop {

	public StoneDrop(int stone) {
		this(GameStaticConfig.defaultChanceBase, 0, stone);
	}
	
	public StoneDrop(int probability, int weight, int stone) {
		this(probability, weight, stone, stone);
	}
	
	public StoneDrop(int probability, int weight, int minStone, int maxStone) {
		this.probability = probability;
		this.weight = weight;
		this.min = minStone;
		this.max = maxStone;
	}

	@Override
	protected void processDrop(Player player, String cause, DropListener listener) {
		int stone = CommonUtils.randomInt(RND, min, max);
		if (stone <= 0) {
			return;
		}
		if (player != null) {
			player.addStone(stone, cause);
		}
		if (listener != null && listener instanceof StoneDropListener) {
			((StoneDropListener) listener).stoneDroped(player, stone);
		}
	}

	public int getStone() {
		return max;
	}

}
